package org.database.filter.model;

import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Person {
	private String name;
	private String birthDay;
	private String CMND;
	private String address;
	private String nationality;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getBirthDay() {
		return birthDay;
	}

	public void setBirthDay(String birthDay) {
		this.birthDay = birthDay;
	}

	public String getCMND() {
		return CMND;
	}

	public void setCMND(String cMND) {
		CMND = cMND;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	/**
	 * @return the nationality
	 */
	public String getNationality() {
		return nationality;
	}

	/**
	 * @param nationality the nationality to set
	 */
	public void setNationality(String nationality) {
		this.nationality = nationality;
	}
	
	public String toString() {
		return "name: "+this.getName()+" nuoc: "+this.getNationality()+" ngay sinh: "+this.getDate()+ " cmnd: "+this.getCMND()+" diachi: "+this.getAddress();
	}
	
	@SuppressWarnings("deprecation")
	public Date getDate() {
		Pattern pp = Pattern.compile("-?\\d+");
		Matcher m = pp.matcher(this.getBirthDay());
		int i = 0;
		Date date = new Date();
		while (m.find()) {
			if(i == 0) {
				date.setDate(Integer.parseInt(m.group()));
			} else if(i == 1) {
				date.setMonth(Integer.parseInt(m.group()));
			} else {
				date.setYear(Integer.parseInt(m.group())-1900);
			}
			i++;						
			System.out.println(m.group());
		}
		return date;
	}
}
